<?php
namespace Home\Controller;

class PostController extends BaseController
{
   public function __construct(){
       parent::__construct();
       $this->assign("citys", $this->_initCity(false));
       $this->assign("categorys",D('Category')->allCategory());
   }
    public function index()
    {
        if (IS_GET) {
            $this->display();
        } else {
            $this->_insertPost();
        }
    }
   
    private function _insertNews(){
        
    }
    private function _insertJianli(){
        $baseMap = array();
        $extMap = array();
        $baseMap['title'] = I('post.title', " ", "trim");
        $baseMap['content'] = I('post.content',"");
        $baseMap['type']  =1;
        //扩展
        $extMap['tel'] = I('post.tel', '', "trim");
        $extMap['qq'] = I('post.qq', 0, 'trim');
        $extMap['email'] = I('post.email', '', 'trim');
        $extMap['province'] = I('post.province', '');
        $extMap['country'] = I('post.country', '');
        $extMap['city'] = I('post.city', '');
        $extMap['channel'] = I('post.channel', 0);
        $extMap['address'] = I('post.address', '', 'trim');
        $baseMap['sex'] =I('post.sex',0,'intval');
        $baseMap['record'] =I('post.record',0,'intval');
        $baseMap['work'] =I('post.work',0,'intval');
        //  $extMap['contact_preson'] = I('post.contact_preson', '', 'trim');
        //  $extMap['xueli'] = I('post.xueli', 0, 'intval');
        //   $extMap['salary'] = I('post.salary', 0, 'intval');
        //    $extMap['is_fee'] = I('post.is_fee', 0, 'intval');
         
        //  $extMap['experience'] = I('post.experience', 0, 'intval');
        // 缺少验证
        $mData = D('Data');
        $baseMap['author'] = $this->userInfo['id'];
        $bool = $mData->insertJianLi($baseMap, $extMap);
        if ($bool == false){
            $map['info']  ="发布失败";
            $map['status'] = "n";
        }else{
            $map['info']  ="发布成功";
            $map['status'] = "y";
        }
        $this->ajaxReturn($map,"JSON");
    }
    private function _insertJianzhi(){  
        $baseMap = array();
        $extMap = array();
        $baseMap['title'] = I('post.title', " ", "trim");
        $baseMap['content'] = I('post.content',"");
        $baseMap['message_from'] =I('post.message_from',0,'intval');
        $baseMap['type']  =I('post.type',0,'intval');
        $extMap['tel'] = I('post.tel', '', "trim");
        $extMap['qq'] = I('post.qq', 0, 'trim');
        $extMap['province'] = I('post.province', '');
        $extMap['country'] = I('post.country', '');
        $extMap['city'] = I('post.city', '');
        $extMap['channel'] = I('post.channel', 0);
        $extMap['address'] = I('post.address', '', 'trim');
        $extMap['email'] = I('post.email', '', 'trim');
      //  $extMap['contact_preson'] = I('post.contact_preson', '', 'trim');
      //  $extMap['xueli'] = I('post.xueli', 0, 'intval');
     //   $extMap['salary'] = I('post.salary', 0, 'intval');
    //    $extMap['is_fee'] = I('post.is_fee', 0, 'intval');
   
      //  $extMap['experience'] = I('post.experience', 0, 'intval');
        // 缺少验证
        $mData = D('Data');
        $baseMap['author'] = $this->userInfo['id'];
        $bool = $mData->insertMessage($baseMap, $extMap);
        if ($bool == false){
           $map['info']  ="发布失败";
           $map['status'] = "n";
        }else{
            $map['info']  ="发布成功";
            $map['status'] = "y";
        }
     $this->ajaxReturn($map,"JSON");
    }

   /* public function area($ajax = true, $region = null)
    {
        $parentid = I("get.region", 1, 'intval');
        $parentid = ($region !== null) ? $region : $parentid;
        $citys = M('region')->where(array(
            'parent_id' => $parentid
        ))->select();
        if ($ajax == false)
            return $citys;
        $html = "";
        foreach ($citys as $k => $v) {
            $html .= "<option value='" . $v['region_id'] . "' >" . $v['region_name'] . "</option>";
        }
        
        echo json_encode($html);
    }*/

    public function jianzhi(){
        if(IS_POST){//post
            $this->_insertJianzhi();
        }
    	$this->assign("citys", $this->_initCity(false));
    	$this->assign("categorys",D('Category')->allCategory());
    	$this->display();
    }
    public function jianli(){
        if(IS_POST){
            $this->_insertJianli();
        }else{
   	        $this->display();
        }
    }
    public function zhaopin(){
    	echo "招聘";
    }
    private function _initCity()
    {
        $province = $this->area(false);
        $city = $this->area(false, $province[0]['region_id']);
        $country = $this->area(false, $city[0]['region_id']);
        //print_r($country);
        return array(
            'province' => $province,
            'citys' => $city,
            'country' => $country
        );
    }
    
    public function postindex(){
    	
    	$this->display();
    }
    
}